package core.evolutionary;

public class Edge {
	private Island fromIsland;
	private Island toIsland;
	private int cost;
	
	public Edge(int cost, Island fromIsland, Island toIsland) throws Exception {
		if(fromIsland == null && toIsland == null)
			throw new Exception("Polaczenie musi posiadac dwie wyspy.");
		if(fromIsland.isElitist())
			throw new Exception("Elitarna wyspa nie ma wychodzacych polaczen.");
		
		this.cost = cost;
		this.fromIsland = fromIsland;
		this.toIsland = toIsland;
	}
	
	public boolean joinsWith(Island island, boolean elitist) {
		return island == this.fromIsland && toIsland.isElitist() == elitist;
	}

	public int getCost() {
		return this.cost;
	}

	public Island getFromIsland() {
		return fromIsland;
	}

	public Island getToIsland() {
		return toIsland;
	}
	
}
